package com.exampl.springstack.common.exceptionUtils.vo;


import com.exampl.springstack.common.exceptionUtils.enums.ResultEnum;
import com.exampl.springstack.common.exceptionUtils.exception.SystemException;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.joda.time.DateTime;



/**
 * @author Qiangfanghao
 */
@Getter
@NoArgsConstructor
public class ResponseResult {

    /**
     * 返回状态码
     */
    private int code;

    /**
     * 错误信息
     */
    private String message;

    /**
     * 数据体
     */

    private Object data;

    /**
     * 时间戳
     */
    private String timestamp;

    /**
     * 异常
     * @param e
     */
    public ResponseResult(SystemException e) {
        this.code = e.getCode();
        this.message = e.getMessage();
        this.timestamp = DateTime.now().toString("yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 手动抛自定义异常
     * @param e
     */
    public ResponseResult(ResultEnum e) {
        this.code = e.getCode();
        this.message = e.getMessage();
        this.timestamp = DateTime.now().toString("yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 返回执行结果
     * @param e
     */
    public ResponseResult(ResultEnum e, Object data) {
        this.code = e.getCode();
        this.message = e.getMessage();
        this.data = data;
        this.timestamp = DateTime.now().toString("yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 无返回值成功
     * @return
     */
    public static ResponseResult ok(){
        return new ResponseResult(ResultEnum.OK);
    }

    /**
     * 有返回值成功
     * @return
     */
    public static ResponseResult ok(Object data){
        return new ResponseResult(ResultEnum.OK,data);
    }


}
